const log4js = require('log4js');
const dayjs = require('dayjs');

/**
 * 创建日志
 */
const createLogInfo = (logStr) => {
  log4js.configure({
      appenders: {
          file: {
              type: 'file',
              filename: `logs/${dayjs().format('YYYY-MM-DD')}/hl_log.log`,
              maxLogSize: 100 * 1024 * 1024, // =100M
              backups: 5,
              compress: true,
              encoding: 'utf-8',
              mode: 0o0640,
              flags: 'a'
          },
          out: {
              type: 'stdout'
          }
      },
      categories: {
          default: {
              appenders: ['file', 'out'],
              level: log4js.levels.ALL
          }
      }
  });
  let logger = log4js.getLogger('anything');
  logger.info(logStr);
}

module.exports = {
    createLogInfo
}
